﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Wicresoft.IDE.Components.Controls
{
    public sealed class RichPanel : Panel
    {
        //private Color _borderColor = Color.FromArgb(23, 169, 254);
        private Color _borderColor = Color.FromArgb(127, 127, 127);

        public RichPanel()
        {
            this.SizeChanged += new EventHandler(RichPanel_SizeChanged);
        }

        void RichPanel_SizeChanged(object sender, EventArgs e)
        {
            if (this.Controls.Count != 1)
                return;

            Control child = this.Controls[0];
            child.Dock = DockStyle.None;

            Rectangle r = ClientRectangle;

            child.Location = new Point(r.X + 2, r.Y + 2);
            child.Size = new Size(r.X + r.Width - 4, r.Y + r.Height - 4);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            GrawBorder(e.Graphics);
        }

        private void GrawBorder(Graphics g)
        {
            Rectangle r = ClientRectangle;
            Point[] points = new Point[5];

            points[0] = new Point(r.X, r.Y);
            points[1] = new Point(r.X + r.Width - 1, r.Y);
            points[2] = new Point(r.X + r.Width - 1, r.Y + r.Height - 1);
            points[3] = new Point(r.X, r.Y + r.Height - 1);
            points[4] = points[0];

            using (Pen pen = new Pen(_borderColor))
            {
                g.DrawLines(pen, points);
            }
        }
    }
}
